<?php
// 测试温度数据API接口

// 生成测试数据
$testData = [
    'timestamp' => time(), // 当前时间戳
    'temperature' => round(20 + (rand(0, 100) / 10), 2), // 随机温度值 20.00-30.00
    'devid' => 'device_' . rand(1000, 9999), // 设备ID
    'devmac' => 'MAC_' . strtoupper(substr(md5(rand()), 0, 12)), // 设备MAC地址
    'token' => md5(rand()), // 随机token
    'param1' => '预留参数1',
    'param2' => '预留参数2',
    'param3' => '预留参数3',
    'param4' => '预留参数4',
    'param5' => '预留参数5'
];

// 将数据转换为JSON
$jsonData = json_encode($testData);

// 使用curl发送POST请求
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://localhost/ksweb_pro/temperature_api.php');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// 输出结果
echo "发送的数据:\n";
echo $jsonData . "\n\n";

echo "HTTP状态码: " . $httpCode . "\n";
echo "API响应:\n";
echo $response . "\n";
?>